import copy
nn=14
mm=[1,2,3]
possolution={}

def calpos(pos, n, m):
    moves=[]
    for i in m:
        postemp = pos+i
        if(postemp<=n):
            moves.append(postemp)
    
    return moves
    
#position create 1
def isWinning(pos, n, m):
    moves=calpos(pos, n, m)
    #print moves
    for x in moves:
        if(isWinning(x, n, m) == True):
            possolution[pos]=False
            return False
    
    possolution[pos]=True
    return True
    
#position create 2
def makepostable(n,m):
    for i in range(0,n+1):
        possolution[i]=True
    
    for i in range(0,n):
        index=n-i
        #print index
        if possolution[index]==True:   
            for x in m:
                if index-x>=0:
                    possolution[index-x]=False
        
def move(pos,n,m,states,idx):
    for x in m:
        postemp = copy.deepcopy(pos)
        postemp+=x
        if postemp>=n:
            return
        isMoveOk = False
        for y in m:
            j=copy.deepcopy(postemp)
            j+=y
            if states[j]==True:
                for i in range(0,idx): print ' ',        
                print 'move',idx,'if opponent takes',x,'-> take',y,',',  
                if n-j+1 <= m[-1]:
                    print 'you win'
                else:
                    print n-j+1,'left' 
                break  
        move(j,n,m,states,idx+1)   
        
def m_nim(n,m):  
    #for i in range (0,n):
     #   possolution[i]=isWinning(i,n-1,m)
    makepostable(nn-m[0],mm)
    if(possolution[0]==True):
        print 'Lost the game'
    
    firstMove = False
    for x in m:
        j=0
        j+=x
        if possolution[j]==True:
            print 'move',1,': take',j,',',n-j,'left'
            firstMove = True
            break
                       
    if(firstMove):       
        move(j,n-1,m,possolution,2)
    else:
        print 'lost game'
            
m_nim(nn,mm)
#makepostable(nn-1,mm)
#print possolution